import { createStore } from 'redux'

//主reducer
const initState = {
  name: '张三', 
  age: 18,
  fruits: []
}
const reducer = (state = initState, action) => {
  if(action.type === 'CHANGE_NAME') {
    return {
      ...state,
      name: action.name
    }
  } else if (action.type === 'CHANGE_AGE') {
    return {
      ...state,
      age: action.age
    }
  }

  if (action.type === 'INIT_FRUITS') {
    // 初始化数据

  }

  if (action.type === 'INIT_FRUITS') {
    return {
      ...state,
      fruits: action.list
    }
  }
  return state
}
// }


const store = createStore(reducer, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__())

export default store